package NewCoder;

public class BM79 {
    public int rob (int[] nums) {
        // write code here
        int n=nums.length;
        if(n==0) return 0;
        return Math.max(rob2(nums,0,n-2),rob2(nums,1,n-1));
    }
    private int rob2(int[] nums,int start,int end){
        int db1=0;
        int db2=0;
        int db=0;
        for(int i=end;i>=start;i--){
            db=Math.max(db1,nums[i]+db2);
            db2=db1;
            db1=db;
        }
        return db;
    }
}
